package com.ztesoft.web.taskgenerator.taskjob;


import java.util.ArrayList;
import java.util.List;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.ztesoft.core.spring.context.SpringApplicationContextHolder;
import com.ztesoft.framework.exception.BaseAppException;
import com.ztesoft.framework.log.ZTEsoftLogManager;
import com.ztesoft.framework.util.Utils;
import com.ztesoft.iocp.job.BaseJob;
import com.ztesoft.iocp.job.JobDesc;
import com.ztesoft.web.taskgenerator.db.po.DmTaskPO;
import com.ztesoft.web.taskgenerator.service.IDmTaskService;
import com.ztesoft.web.taskgenerator.service.impl.DmTaskServiceImpl;

public class TaskJob extends BaseJob{
	 private static final ZTEsoftLogManager logger = ZTEsoftLogManager
	            .getLogger(TaskJob.class);
	@Override
	public void execute(JobExecutionContext context,JobDesc jobDesc) throws JobExecutionException {
		IDmTaskService iDmTaskService = SpringApplicationContextHolder.getBean(DmTaskServiceImpl.class);
		DmTaskFatherJob dmTaskFatherJob = SpringApplicationContextHolder.getBean(DmTaskFatherJob.class);
		DmTaskSubJob dmTaskSubJob = SpringApplicationContextHolder.getBean(DmTaskSubJob.class);
		try {
			List<DmTaskPO> dmSubTask = iDmTaskService.selectByNeedSubtask();
			logger.debug("生成子任务dmSubTask"+dmSubTask);
			if(!Utils.isEmpty(dmSubTask)){//需要子任务,生成派生子任务
				dmTaskSubJob.createSubTask(dmSubTask);
			}else{
				dmTaskFatherJob.createFatherTask();//fu任务生成
			}
		} catch (BaseAppException e) {
			logger.error("||TaskJob execute||"+e);
		}
	}
			
}
